package io.xxx.mario.task.receive;

import io.xxx.mario.task.ReceiverType;
import io.xxx.mario.task.client.StoreClient;
import io.xxx.mario.task.client.model.Store;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Slf4j
@Component
public class RoomReceiverFilter implements Receiver.Filter {

    @Resource
    private StoreClient storeClient;

    @Override
    public boolean doFilter(Receiver receiver) {
        Optional<Store> store = storeClient.getStore(receiver.id());
        return store.map(value -> value.getStatus() == Store.Status.NORMAL)
                .orElseGet(() -> {
                    log.info("门店状态错误");
                    return false;
                });
    }

    @Override
    public boolean support(Receiver receiver) {
        return receiver.type() == ReceiverType.ROOM;
    }
}
